package org.esky.xml;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class DomXMLReader {

	/**
	 * DOM方式
	 * 
	 * @Title: reader
	 * @Description: TODO
	 * @param path
	 * @return: void
	 */
	public static void reader(String path) {
		long lasting = System.currentTimeMillis();
		try {
			File f = new File(path);
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			Document doc = builder.parse(f);
			NodeList nl = doc.getElementsByTagName("node");
			for (int i = 0; i < nl.getLength(); i++) {
				System.out.println("|| Name:  |" + doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue());
				System.out.println("||Space:  |" + doc.getElementsByTagName("space").item(i).getFirstChild().getNodeValue());
				System.out.println("-------------------------------------------------");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("DOM RUNTIME：" + (System.currentTimeMillis() - lasting) + " MS");
	}
}
